><

Lines, characters, and selections



The Source Editor window contains Line and Character objects. These objects represent physical lines or characters, which can be addressed as single entities or in groups. You can use the standard AppleScript syntax to address lines and characters:

Line 1 Character 1234 the last Line Characters 10 thru 20 of Line 11

The Character object exists either at the document or line level. At the document level, it refers to a single character within the document, starting at position 1. At the line level, it refers to a single character on the specified line, starting at position 1. Both the line and column or character specifications start at position 1.

The Selection object reflects the current selection. The selection is invalid if nothing is selected. This sets the Is Visible property of the selection to false.

You can create a selection in many ways--for example, by manipulating the Starting Point or Ending Point properties of the Selection object or by using the Select command. The Select command requires a line or character object or a from/to specification such as "from {line,column} to {line, column}". All Paste operations select the pasted text by default.

To delete the current selection, use the Delete Selection or Delete commands; the Deselect command cancels the current selection.

All objects have Property Contents to allow direct access to their content. The Length property indicates the number of characters in the object.

Line and Character objects have additional common properties. The Index property indicates the number of an object, the number of a line, or the position of a character within a document.


Automating Operations Using AppleScript > Lines, characters, and selections